package com.doumuxie.util;

import org.springframework.beans.BeanUtils;

/**
 * 自定义dto 复制工具类
 */
public class BeanUtil {

    public static <V> V copy(Object source, Class<V> target) {
        try {
            // 实例化dto
            V v = target.newInstance();
            // 复制属性
            BeanUtils.copyProperties(source, v);
            return v;
        } catch (Exception e) {
            throw new RuntimeException("copy bean fail", e);
        }
    }

//    public static void main(String[] args) {
//        User user = new User("123",1,1,1,"1");
//        user.setCreateTime(new Date());
//        UserDto copy = copy(user, UserDto.class);
//        System.err.println(JSON.toJSONString(copy));
//    }

}
